import { _decorator, Component, find, instantiate, Node, Prefab, UITransform } from 'cc';
import { GameManager, GameState } from '../GameManager';
const { ccclass, property } = _decorator;

@ccclass('Ships_Void')
export class Ships_Void extends Component {

    @property(Prefab)
    bullet_3: Prefab = null;

    private lastBulletTime: number = 0; // 上一次生成子弹的时间

    start() {

    }

    update(deltaTime: number) {
        const currentTime = Date.now();
        if (currentTime - this.lastBulletTime >= 2000) {
            this.lastBulletTime = currentTime;
            if(GameManager.getInstance().gameState==GameState.START){
                this.attack();
            }
        }
    }

    attack() {
        if(this.bullet_3){
            const newBullet=instantiate(this.bullet_3);
            const PlayerBullets=find("Canvas/BG/Bullets");
            PlayerBullets.addChild(newBullet);

            const newPos=this.node.getWorldPosition();
            newBullet.setWorldPosition(newPos);
        }

    }
}
